#include <stdio.h>
#include <stdlib.h>
typedef  char dataType;
typedef struct BtreeNode {
    dataType data;
    struct BtreeNode *left;
    struct BtreeNode *right;
}BtreeNode,*Btree;

// 创建节点
Btree createBtree(dataType ch) {
    Btree newNode = (Btree) malloc(sizeof(BtreeNode));
    if(newNode==NULL) {
        printf("错误：节点为空\n");
        return NULL;
    }
    newNode->data = ch;
    newNode->left = NULL;
    newNode->right = NULL;
    return newNode;
}

// 打印树的高度（就是层数）
int GetHeight(Btree t) {
    if(t==NULL) {
        return 0;
    }
    if(t->left == NULL && t->right == NULL){
        return 1;
    }
    return GetHeight(t->left) > GetHeight(t->right) ? GetHeight(t->left) + 1 : GetHeight(t->right) + 1;
}

// 打印树的叶子结点数（没有子节点‌的节点）
int GetCount(Btree t) {
    if(t==NULL) {
        return 0;
    }
    if(t->left == NULL && t->right == NULL) {
        return 1;
    }
    return GetCount(t->left) + GetCount(t->right);
}

int main() {
#ifdef _WIN32
    system("chcp 65001 > null");
#endif

    // 创建示例二叉树:
    //       1
    //      / \
    //     2   3
    //    / \
    //   4   5
    Btree root = createBtree(1);
    root->left = createBtree(2);
    root->right = createBtree(3);
    root->left->left = createBtree(4);
    root->left->right = createBtree(5);

    printf("树的高度是：%d\n", GetHeight(root));
    printf("树的叶子结点数是：%d\n", GetCount(root));
    return 0;
}
